home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
tcoop10a.zip
/
DEMO.ZIP
/
TESTITEM.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1991-11-20
|
2KB
|
90 lines
//
// TESTITEM.CPP
// version 1.00 11/10/91
// uses LIST.CPP for List Class
// copyright (c) 1991 by James S. Clark
// all rights reserved
//
// #include <string.h>
#include "list.hpp"
#include "item.hpp"
void printall(List *list)
{
int i;
for (i=0; i<list->count(); i++)
((Item *) list->get(i))->print();
puts("");
}
void printallback(List *list)
{
Item *current = (Item *) list->last;
int i;
while (current) {
current->print();
current = (Item *) current->previous;
}
puts("");
}
int main()
{
List *list = new List(Item::compare); // create a new list and
// pass it a compare func
Item *test1, *test2;
int i;
// this creates two items and add them to the list
test1 = new Item("Test1 - Item1");
list->add(test1);
test2 = new Item("Test1 - Item2");
list->add(test2);
test2->print();
list->destroy();
// this does the job on one line
test1 = (Item *) list->add(new Item("Test2 - Item 1"));
test2 = (Item *) list->add(new Item("Test2 - Item 2"));
test2->print();
list->destroy();
// you can create a list and 'get' the Items later
list->add(new Item("Test3 - Item1"));
list->add(new Item("Test3 - Item2"));
test1 = (Item *) list->get(0);
test1->print();
list->destroy();
// you can create a list using operator overloading
*list + new Item("Test4 - Item1")
+ new Item("Test4 - Item4")
+ new Item("Test4 - Item2")
+ new Item("Test4 - Item3");
printf("%d is the count\n", list->count());
printall(list);
//
// the sort method is still a bit buggy.
// it loses the original pointer...
// list->sort();
//
test1 = (Item *) list->get(2);
list->add(test1, new Item("Test4 - *****"));
printall(list);
printallback(list);
delete list; // free the list object
return(0);
}